﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.ServiceModel.Security;
using System.IdentityModel.Selectors;
using Sinacor.Infra.Common.Security.Authentication.Credentials;

namespace Sinacor.Infra.Service.Security.Authentication.ServiceCredentials
{
    internal class SinacorServiceCredentialsSecurityTokenManager :
        ServiceCredentialsSecurityTokenManager
    {
        SinacorServiceCredentials credentials;

        public SinacorServiceCredentialsSecurityTokenManager(SinacorServiceCredentials credentials)
            : base(credentials)
        {
            this.credentials = credentials;
        }

        public override SecurityTokenAuthenticator CreateSecurityTokenAuthenticator(SecurityTokenRequirement tokenRequirement, out SecurityTokenResolver outOfBandTokenResolver)
        {
            if (tokenRequirement.TokenType == Constants.SinacorTokenType)
            {
                outOfBandTokenResolver = null;
                return new SinacorTokenAuthenticator();
            }

            return base.CreateSecurityTokenAuthenticator(tokenRequirement, out outOfBandTokenResolver);
        }

        public override SecurityTokenSerializer CreateSecurityTokenSerializer(SecurityTokenVersion version)
        {
            return new SinacorTokenSerializer(version);
        }
    }

}
